package com.hoppinzq.controller;

import com.hoppinzq.bean.TestBean;
import com.hoppinzq.service.TestService;
import com.hoppinzq.service.common.UserPrincipal;
import com.hoppinzq.service.proxy.ServiceProxyFactory;
import com.hoppinzq.service.util.JSONUtil;
import com.hoppinzq.service.utils.RpcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

/**
 * @author ZhangQi
 */
@RestController
public class TestController {

    public String getValue(){
        return "value";
    }

    @RequestMapping("/demo")
    public String test(){
        RpcTemplate.setRequestHeader("traceId","zha123123ngqi");
        UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
        TestService testService = ServiceProxyFactory
                .createProxy(TestService.class,
                        "http://127.0.0.1:8811/service",upp);
        String str=JSONUtil.format(testService.getTraceId());
        System.err.println(RpcTemplate.getResponse().getStatus());
        Map<String,Object> responseHeader = RpcTemplate.getResponse().getHeaders();
        System.err.println(responseHeader.get("x-rpc-trace"));

        TestBean testBean=new TestBean();
        testBean.setName("ZhangQi");
        testService.getBeanName(testBean);
        System.err.println(testBean.getAge());
        return str;
    }

}